package com.seewo.dubbo.debugger.admin.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.seewo.dubbo.debugger.admin.common.validate.group.Query;
import com.seewo.dubbo.debugger.admin.common.validate.group.Update;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *
 * </p>
 *
 * @author chenliangliang
 * @since 2018-07-25
 */
@Data
@Accessors(chain = true)
@TableName("t_interface")
public class Interface implements Serializable {

    private static final long serialVersionUID = -6005319759269438692L;

    @TableId(value = "c_id", type = IdType.AUTO)
    @NotNull(message = "接口id不能为空", groups = {Update.class})
    @Min(message = "cid不合法", value = 0, groups = {Update.class})
    private Integer cId;
    @NotNull(message = "serviceId不能为空", groups = {Query.class})
    private Integer cServiceId;
    /**
     * dubbo接口url
     */
    @JSONField(serialize = false, deserialize = false)
    private String cUrl;
    /**
     * 接口名
     */
    @NotBlank(message = "接口名不能为空", groups = {Query.class})
    private String cName;
    @NotBlank(message = "要更新的描述不能为空", groups = {Update.class})
    private String cDesc;
    @JSONField(serialize = false, deserialize = false)
    private Date cCreateTime;
    @JSONField(serialize = false, deserialize = false)
    private Date cUpdateTime;

    private String cVersion;

    @TableField(exist = false)
    private List<Method> methods;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Interface)) return false;
        Interface that = (Interface) o;
        return Objects.equals(cServiceId, that.cServiceId) &&
                Objects.equals(cName, that.cName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(cServiceId, cName);
    }
}
